import request from '@/utils/request'
import type {
  AllSaleAttrRes,
  AllTrademark,
  HasSpuResponseData,
  SkuData,
  SpuData,
  SpuImageRes,
  SpuSaleAttrRes,
  SkuInfoData,
} from './type'

enum API {
  //获取已有的spu数据
  HASSPU_URL = '/admin/product/',
  //获取全部品牌的数据
  ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  //获取某个spu全部的售卖商品的图片数据
  IMAGE_URL = '/admin/product/spuImageList/',
  //获取某个spu的全部已有的销售属性
  SPUHASSSPUALETTR_URL = '/admin/product/spuSaleAttrList/',
  //获取整个项目全部的销售属性
  ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
  //追加一个新的spu
  ADDSPU_URL = '/admin/product/saveSpuInfo',
  //更新一个spu
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  //追加一个新增的SKU地址
  ADDSKU_URL = '/admin/product/saveSkuInfo',
  //查看某一个已有的SPU下全部售卖的商品
  SKUINFO_URL = '/admin/product/findBySpuId/',
  //删除已有的SPU
  REMOVESPU_URL = '/admin/product/deleteSpu/',
}
export const reqhasSpu = (
  page: number,
  limit: number,
  category3Id: number | string,
) =>
  request.get<any, HasSpuResponseData>(
    API.HASSPU_URL + `${page}/${limit}/?category3Id=${category3Id}`,
  )
//获取全部品牌的数据
export const reqAllTrademark = () =>
  request.get<any, AllTrademark>(API.ALLTRADEMARK_URL)
//获取某个spu的全部售卖商品的图片数据
export const reqSpuImageList = (spuId: number) =>
  request.get<any, SpuImageRes>(API.IMAGE_URL + spuId)
//获取某个spu的全部已有的销售属性
export const reqSpuSaleAttrList = (spuId: number | string) =>
  request.get<any, SpuSaleAttrRes>(API.SPUHASSSPUALETTR_URL + spuId)
//获取整个项目全部的销售属性
export const reqAllSaleAttr = () =>
  request.get<any, AllSaleAttrRes>(API.ALLSALEATTR_URL)

//更新一个spu
//添加一个新的spu
export const reqAddUpdateSpuu = (data: SpuData) => {
  if (data.id) {
    return request.post<any, any>(API.UPDATESPU_URL, data)
  } else {
    return request.post<any, any>(API.ADDSPU_URL, data)
  }
}
//追加一个新增的SKU地址
export const reqAddSku = (data: SkuData) =>
  request.post<any, any>(API.ADDSKU_URL, data)
//获取SKU数据
export const reqSkuInfo = (spuId: number | string) =>
  request.get<any, SkuInfoData>(API.SKUINFO_URL + spuId)
//删除一个spu
export const reqRemoveSpu = (spuId: number | string) =>
  request.delete<any, any>(API.REMOVESPU_URL + spuId)
